import java.sql.*;

public class DatabaseOperator {
    transient Connection connection = null;
    transient Statement sql = null;
    transient ResultSet rs = null;
    public DatabaseOperator(String conn_str){
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
        }catch (Exception e){
           e.printStackTrace();
        }
        try {
            connection = DriverManager.getConnection(conn_str);
            sql = connection.createStatement();
            rs = sql.executeQuery("select * from goods;");

            while(rs.next()){
                int id = rs.getInt(1);
                String type = rs.getString(2);
                String name = rs.getString(3);
                double price = rs.getDouble(4);
                int count = rs.getInt(5);
                String time = rs.getString(6);
                System.out.printf("%d\t%s\t%s\t%.2f\t%d\t%s\n",id,type,name,price,count,time);
            }
            connection.close();
        } catch (SQLException sqle) {
            sqle.printStackTrace();
        }
    }
}
